#!/bin/bash 
set -e


TMP=${TMP:-/tmp/work}
LOG=${LOG:-$HOME/logs/stage4}
SRC=${SRC:-/sources}

name=cmake
version=3.19.4

rm -rf $TMP
mkdir -p $TMP $LOG

tar xf $SRC/$name-$version.tar.gz -C $TMP

{ time \
   {

    cd $TMP/$name-$version
    
	sed -i '/"lib64"/s/64//' Modules/GNUInstallDirs.cmake

	./bootstrap --prefix=/usr        \
	            --system-libs        \
	            --mandir=/share/man  \
	            --no-system-jsoncpp  \
	            --no-system-librhash \
	            --docdir=/share/doc/$name-$version \
	            --parallel=
	make

	make install

    }
} 2>&1 | tee $name.log
    
[ $PIPESTATUS = 0 ] && mv $name.log $LOG || exit $PIPESTATUS

rm -fr $TMP
